@sec-ant/readable-stream
A Simple Yet Spec-Compliant Asynchronous Iteration Polyfill for ReadableStream
s from Web Streams API
Features
Async Iteration of a ReadableStream
With this polyfill, you'll be able to consume a ReadableStream
as an AsyncIterable
.
Construction of a ReadableStream
from an AsyncIterable
or an Iterable
You can use the function fromIterable
in this package to construct a ReadableStream
from an AsyncIterable
or an Iterable
. This mimics the static method ReadableStream.from
.
This package passes all the aforementioned tests.
Install
npm i @sec-ant/readable-stream
Usage
This package can be used as a side effect if you only need the async iteration support:
import "@sec-ant/readable-stream";
You can also import the fromIterable
function which enables you to construct a ReadableStream
from an Iterable
or an AsyncIterable
:
import { fromIterable } from "@sec-ant/readable-stream";
With the help of this package, you can "tee
" an AsyncIterable
like this:
import { fromIterable } from "@sec-ant/readable-stream";
async function* createAsyncIterable() {
yield "how";
yield "are";
yield "you";
}
const asyncIterable = createAsyncIterable();
const [asyncIterable1, asyncIterable2] = fromIterable(asyncIterable).tee();
License
MIT